<!DOCTYPE html>
<html>
<head>
	{include file="top.tpl"}
	<link href="{$js.url}plugins/multiselect/css/bootstrap-multiselect.css" rel="stylesheet" type="text/css" />
	{literal}
    <style>
    	body{font-family: 'Microsoft yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif;}
	</style>
	{/literal}
</head>
<body class="skin-blue">
<div class="wrapper">
{include file="bread_crumbs.tpl"}
	<!--引入面包屑-->
	<section class="base-setting-wrap">
		<div class="row">
			<div class="col-md-12">
				<div class="box">
	                <div class="box-header with-border clearfix">
	                	<div class="box-form pull-right form-group-sm">
	                		<p class="pull-right"><a href="javascript:;" class="btn btn-success btn-sm" id="js_toggleSearchBox"><i class="fa fa-search"></i><span class="pl5">搜索选项</span></a></p>
	                	</div>
	                	<div class="clearfix"></div>
						<div class="search-box" id="js_searchBox">
							<form method="get" action="/backup/rule/list" class="auto-restore form-inline">
								<div class="form-group-sm">
									<p>
										<label class="control-label">生效时间：</label>
										<input class="form-control date_start" name="start_date"/>-<input class="form-control date_end" name="end_date" />
										<label class="control-label">适用仓库：</label>
										<select class="form-control" id="warehouseDepartment" name="warehouse_department">
											  <option value="0">所有</option>
									              {foreach from=$warehouseDep key=depId item=depName}
									                <option value="{$depId}" {if $queryParameter['department']|default:0 && ($queryParameter['department'] == $depId)} selected="selected" {/if} >{$depName}</option>
									              {/foreach}
										</select>

										<select class="form-control ml10" id="departmentWarehouse" name="warehouse[]">
											<option value="0">请选择仓库</option>
										</select>

										<label class="control-label">启用状态：</label>
										<select class="form-control" name="is_enable">
											<option value="0">所有</option>
											<option value="1">启用</option>
											<option value="2">停用</option>
										</select>

										<label class="control-label">优先级别：</label>
										<select class="form-control" name="priority">
											<option value="0">所有</option>
											<option value="1">1</option>
											<option value="2">2</option>
											<option value="3">3</option>
											<option value="4">4</option>
											<option value="5">5</option>
										</select>

										<button type="submit" class="btn btn-primary btn-sm">查询</button>
                                        <a href="/backup/rule/add"><button type="button" class="btn btn-primary btn-sm">新建规则</button></a>
									</p>
								</div>
							</form>
						</div>
	                </div>
	                <!-- /.box-header -->

	                <div class="box-body">


	                  <table class="table table-bordered table-striped table-hover">
	                  	<thead>
	                    <tr>
	                      <th >是否启用</th>
	                      <th >规则名称</th>
	                      <th >优先级别</th>
	                      <th >事业部</th>
	                      <th >适用仓库</th>
	                      <th >生效日期</th>
	                      <th >截止日期</th>
	                      <th >添加人</th>
	                      <th >描述</th>
	                      <th >操作</th>

	                    </tr>
	                    </thead>
	                    {foreach from=$ruleList item=rule}
	                    <tr>
							<td>
							{if $rule['is_enable']==1}
							 是
							{else}
							 否
							{/if}
							</td>
							<td>{$rule['name']}</td>
							<td>{$rule['priority']}</td>
							<td>{$rule['warehouseDepName']}</td>
							<td>{$rule['allWarehouseName']}</td>
							<td>{$rule['start_date']}</td>
							<td>{$rule['end_date']}</td>
							<td>{$rule['creator']}</td>
							<td>{$rule['description']}</td>
							<td>
								<div class="row">
								    {if  $rule['is_enable']==1}
									<div class="col-sm-3"><a class="btn btn-primary btn-sm" href="javascript:;" onClick="turnOffRule({$rule['id']})" data-toggle="tooltip" title="停用"><span class="glyphicon glyphicon-pause"></span></a></div>
									{elseif $rule['is_enable']==2}
									<div class="col-sm-3"><a class="btn btn-primary btn-sm" href="javascript:;" onClick="turnOnRule({$rule['id']})" data-toggle="tooltip" title="启用"><span class="glyphicon glyphicon-pause"></span></a></div>
									{/if }
									<div class="col-sm-3"><a class="btn btn-primary btn-sm" href="/backup/rule/edit/?ruleId={$rule['id']}" target="main_frame" data-toggle="tooltip" title="编辑"><span class="glyphicon glyphicon-edit"></span></a></div>
									<div class="col-sm-3"><a class="btn btn-primary btn-sm" href="/backup/rule/view/?ruleId={$rule['id']}" target="main_frame" data-toggle="tooltip" title="查看"><span class="glyphicon glyphicon-eye-open"></span></a></div>
									<div class="col-sm-3"><a class="btn btn-primary btn-sm" href="javascript:;" onclick="isCopy({$rule['id']})" target="main_frame" data-toggle="tooltip" title="复制"><span class="glyphicon glyphicon-copy"></span></a></div>
								</div>
							</td>
						</tr>
						{/foreach}
	              	</table>
	                </div>
	                <!-- .box-body -->
	                <div class="box-footer text-center clearfix">
					{$pageLink}
	                </div>
	              </div>
			</div>
		</div>
	</section>
	<div id="rule_turn_on_date" style="display:none;width:300px;;padding-top:10px;padding-left:10px;">
		<div class="form-group">
			开始日期:<input class="form-control rule_date_start" id="rule_start_date" style="width:230px;" />结束日期：<input class="form-control rule_date_end" id="rule_end_date" style="width:230px;" />
		</div>
    </div>
</div>
{include file='foot.tpl'}
<script src="{$js.url}app_widget/warehouse.js"></script>
<script src="{$js.url}plugins/multiselect/js/bootstrap-multiselect.js"></script>
<script>
{literal}
$(function(){
	$('.date_start').datetimepicker({
	    format: "yyyy-mm-dd",
        minView:2,
        autoclose: true,
        todayHighlight: false
	}).on('changeDate', function(ev){
        $(".date_end").val("").datetimepicker('setStartDate',$(this).val());
    });
    $('.date_end').datetimepicker({
	    format: "yyyy-mm-dd",
        minView:2,
        autoclose: true,
        todayHighlight: false
	});
});

$(function(){
	$('.rule_date_start').datetimepicker({
	    format: "yyyy-mm-dd",
        minView:2,
        autoclose: true,
        todayHighlight: false,
        startDate:new Date()
	}).on('changeDate', function(ev){
        $(".rule_date_end").val("").datetimepicker('setStartDate',$(this).val());
    });
    $('.rule_date_end').datetimepicker({
	    format: "yyyy-mm-dd",
        minView:2,
        autoclose: true,
        todayHighlight: false
	});
});

//停启用备货规则
function turnOffRule(ruleId){
	layer.confirm('您确定停用选择的备货规则？', {
	  btn: ['确定','取消'] 
	}, function(){
		$.ajax({
		   type:"GET",
		   url:"/backup/rule/turn-off?ruleId="+ruleId,
		   dataType:"json",
		   success: function(result){
		   	  layer.alert(result.msg,function(index){
			   	  if(result.status=='success'){
			   	  	 document.location.reload() ;
			   	  }
			   	  layer.close(index);
		   	  });
		   }
		});
	}, function(){
   	  layer.closeAll();
	});
}

//停启用备货规则
function turnOnRule(ruleId){
	var confirm_layer_index=layer.confirm('您确定启用选择的备货规则？', {
	  btn: ['确定','取消'] 
	}, function(){
		layer.close(confirm_layer_index);
		layer.open({
		        type: 1,
		        title:'规则有效时间',
		        area: ['300px', '250px'], //宽高
		        zIndex : 1000,
		        content: $("#rule_turn_on_date"),
		        btn: ['确定', '取消'],
		        yes:function() {
		        	var start_date = $("#rule_start_date").val();
		        	var end_date = $("#rule_end_date").val();
					if (start_date && end_date) {
							$.ajax({
							   type:"GET",
							   url:"/backup/rule/turn-on?ruleId="+ruleId+"&endDate="+end_date+"&startDate="+start_date,
							   dataType:"json",
							   success: function(result){
							   	  layer.alert(result.msg,function(index){
								   	  if(result.status=='success'){
								   	  	 document.location.reload() ;
								   	  }
								   	  layer.close(index);
							   	  });
							   }
						   });
					} else {
						layer.alert("请填写规则的启用时间！");
					}
					return false;
		        }
           });
	}, function(){
   	  layer.close(confirm_layer_index);
	});
}

function isCopy(rId){
	layer.confirm('您确定是否复制选择的备货规则？', {
		btn: ['确定','取消'] 
	}, function(){
		window.location.href = '/backup/rule/copy/?ruleId='+rId;
	});
}

$(document).ready(function(){
	//仓库查询条件复原预选中
	depWarehouse=new DepartmentWarehouse("warehouseDepartment","departmentWarehouse",true);
	depWarehouse.init();
	depWarehouse.hasSelectWarehouse(GLOBAL.getUrlParam('warehouse[]'),GLOBAL.getUrlParam('warehouse_department'));
});

{/literal}
</script>
<script src="{$js.url}form_helper.js"></script>
</body>
</html>
